package com.xiaoshuidi.cloud.module.member.enums.coupon;

import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.annotation.EnumValue;
import com.baomidou.mybatisplus.annotation.IEnum;
import com.xiaoshuidi.cloud.module.member.enums.QuestionTypeEnum;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Alex
 * @description 优惠券状态
 * @date 2022/12/5 16:45
 */
@Getter
@AllArgsConstructor
public enum CouponStatusEnum implements IEnum<Integer> {

    NOT_SUBMITTED(1, "未提交"),
    BEING_APPROVED(2, "审核中"),
    APPROVAL_REJECTION(3, "审批驳回"),
    NOT_STARTED(4, "未开始"),
    IN_PROGRESS(5, "进行中"),
    TERMINATED(6, "已终止"),
    COMPLETED(7, "已结束"),
    APPROVAL_NO_PASS(8, "审批不通过"),
    APPROVAL_CANCEL(9, "审批取消");
    @EnumValue
    private final Integer code;
    private final String desc;
    private static Map<Integer, CouponStatusEnum> enumMap = new HashMap<>();

    static {
        CouponStatusEnum[] values = CouponStatusEnum.values();
        for (CouponStatusEnum value : values) {
            enumMap.put(value.getCode(), value);
        }
    }

    public static CouponStatusEnum getEnum(Integer num) {
        return enumMap.get(num);
    }

    @Override
    public Integer getValue() {
        return code;
    }

    public static Integer getCouponStatusByCode(int code) {
        CouponStatusEnum[] couponStatusEnums = values();
        for (CouponStatusEnum couponStatusEnum : couponStatusEnums) {
            if (couponStatusEnum.code == code) {
                return couponStatusEnum.code;
            }
        }
        return null;
    }

    public static String getDescByCode(Integer code) {
        CouponStatusEnum couponStatusEnum = Arrays.stream(CouponStatusEnum.values()).filter(p -> p.code.intValue() == code.intValue()).findFirst().orElse(null);
        Assert.isTrue(couponStatusEnum != null, "CouponStatusEnum:{}不存在", code);
        return couponStatusEnum.getDesc();
    }

}
